'use strict';
const {
  makeRequest,
  mixArgs,
  mixArgs_nodefault,
  add,
} = require('../src/main.js');

var assert = require('assert');
require('mocha-sinon');

describe('Better Unicode Support', function () {
  afterEach(function () {});
  beforeEach(function () {
    //this.sinon.stub(console, 'log');
    this.sinon.spy(console, 'log');
  });

  it('should Default Parameter Values in ECMAScript 6', function (done) {
    makeRequest('/foo');
    assert.strictEqual(console.log.callCount, 3);
    assert.strictEqual(console.log.args[0][0], '/foo');
    assert.strictEqual(console.log.args[1][0], 2000);
    assert.strictEqual(console.log.args[2][0].name, 'callback');

    makeRequest('/foo', 100);
    assert.strictEqual(console.log.callCount, 6);
    assert.strictEqual(console.log.args[3][0], '/foo');
    assert.strictEqual(console.log.args[4][0], 100);
    assert.strictEqual(console.log.args[5][0].name, 'callback');

    makeRequest('/foo', undefined);
    assert.strictEqual(console.log.callCount, 9);
    assert.strictEqual(console.log.args[6][0], '/foo');
    assert.strictEqual(console.log.args[7][0], 2000);
    assert.strictEqual(console.log.args[8][0].name, 'callback');

    mixArgs('a');
    assert.strictEqual(console.log.callCount, 14);
    assert.strictEqual(console.log.args[9][0], 1); //arguments.length
    assert.strictEqual(console.log.args[10][0], true); //first === arguments[0]
    assert.strictEqual(console.log.args[11][0], false); //second === arguments[1]
    assert.strictEqual(console.log.args[12][0], false); //first === arguments[0]
    assert.strictEqual(console.log.args[13][0], false); //second === arguments[1]

    mixArgs_nodefault('a', 'b'); //严格模式下，arguments与参数名称绑定
    assert.strictEqual(console.log.callCount, 19);
    assert.strictEqual(console.log.args[14][0], 2); //arguments.length
    assert.strictEqual(console.log.args[15][0], true); //first === arguments[0]
    assert.strictEqual(console.log.args[16][0], true); //second === arguments[1]
    assert.strictEqual(console.log.args[17][0], false); //first === arguments[0]
    assert.strictEqual(console.log.args[18][0], false); //second === arguments[1]

    done();
  });
  it('should TDZ', function (done) {
    console.log(add(1, 1)); // 2
    console.log(add(undefined, 1)); // throws an error
    //The call to add(undefined, 1) throws an error because second is defined after first and is therefore unavailable as a default value.
    done();
  });
  it('should Increased Capabilities of the Function Constructor', function (done) {
    var pickFirst = new Function('...args', 'return args[0]');
    assert.strictEqual(pickFirst(1, 2), 1); // 1
    done();
  });
  it('should The Spread Operator', function (done) {
    let values = [-25, -50, -75, -100]
    assert.strictEqual(Math.max(...values, 0), 0);//使用...将对象分割
    done();
  });
  it('should Special Cases of the name Property', function (done) {
    function A(){

    }
    let a = new A();
    assert.strictEqual(A.name, 'A');//name属性会显示恰当的函数名称，但只用来提供信息，不代表函数的引用
    done();
  });
  
  
});
